import QtQuick 1.1
import QtMobility.sensors 1.2
import com.nokia.meego 1.1

PageStackWindow {
	id: appWindow

	initialPage: tabPage

	// Use appWindow.appVisible to check if the application is visible,
	// including in the task switcher.
	// The Qt.application.active-part makes the app "visible" in the simulator.
	property bool _appVisible: false
	property bool appVisible: _appVisible || Qt.application.active

	Connections {
		target: platformWindow
		onVisibleChanged: _appVisible = platformWindow.visible
	}

	// PersistentObject for the settings.
	PersistentObject {
		id: settings

		// Signals whenever the settings have been changed.
		// BUG: However, it's not possible (due to bug in Qt?) to listen for changes
		// here. So, an "onLatitudeChanged" here simply won't work. Only where the actual
		// properties are defined, onXChanged handlers are functional.
		// @see SettingsPage
		signal settingsUpdated

		property alias latitude: settingsPage.latitude
		property alias longitude: settingsPage.longitude
		property alias locationName: settingsPage.locationName
		property alias compassMode: settingsPage.compassMode
		onSettingsUpdated: console.log('Settings updated')
	}



	Page {
		id: tabPage
		orientationLock: PageOrientation.LockPortrait

		tools: ToolBarLayout {

			ButtonRow {
				anchors {
					left: parent.left
					right: menuButton.left}

				platformStyle: TabButtonStyle { }
				TabButton {
                    text: qsTr("Nu")
					tab: buienradarPage
				}

				TabButton {
                    text: qsTr("2 uur")
					tab: shorttermPage
				}

				TabButton {
                    text: qsTr("2 weken")
					tab: longtermPage
				}
			}

			ToolIcon {
				id: menuButton
				iconId: "toolbar-view-menu"
				onClicked: {
					if (menu.status === DialogStatus.Closed) {
						menu.open();
					} else {
						menu.close();
					}
				}
			}
		}

		TabGroup {
			id: tabs

			currentTab: buienradarPage

			BuienradarPage {
				id: buienradarPage
			}

			ShorttermPage {
				id: shorttermPage
			}

			LongtermPage {
				id: longtermPage
			}
		}
	}

	AboutPage {
		id: aboutPage
	}

	SettingsPage {
		id: settingsPage
	}

	QueryDialog {
		id: showSettingsDialog
        titleText: qsTr("Kies een locatie")
        message: qsTr("De prognoses zijn op maat gemaakt voor een locatie. Er is echter nog geen locatie ingesteld.")
        acceptButtonText: qsTr("Open locatie-instellingen")
		onAccepted: pageStack.push(settingsPage)
	}

	Menu {
		id: menu
		visualParent: tabs.currentTab
		content: MenuLayout {
			MenuItem {
                text: qsTr("Over Buienradar")
				onClicked: pageStack.push(aboutPage)
			}

			MenuItem {
                text: qsTr("Bezoek buienradar.nl")
				onClicked: Qt.openUrlExternally("http://buienradar.nl/")
			}

			MenuItem {
                text: qsTr("Instellingen")
				onClicked: pageStack.push(settingsPage)
			}
		}
	}

	Compass {
		id: compass
		active: false
	}
}
